package com;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

public class jfrechart
{
	public static void main(String s[])
	{
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset.setValue(6, "Profit1", "Jane");
		dataset.setValue(3, "Profit2", "Jane");
		dataset.setValue(7, "Profit1", "Tom");
		dataset.setValue(10, "Profit2", "Tom");
		dataset.setValue(8, "Profit1", "Jill");
		dataset.setValue(8, "Profit2", "Jill");
		dataset.setValue(5, "Profit1", "John");
		dataset.setValue(6, "Profit2", "John");
		dataset.setValue(12, "Profit1", "Fred");
		dataset.setValue(5, "Profit2", "Fred");

		// Profit1, Profit2 represent the row keys
		// Jane, Tom, Jill, etc. represent the column keys

		JFreeChart chart = ChartFactory.createBarChart3D(
		   "Comparison between Salesman",  // Chart name
		   "Salesman",                     // X axis label
		   "Value ($)",                    // Y axis value
		   dataset,                        // data set
		   PlotOrientation.VERTICAL,
		   true, true, false);

		// Creating a JPEG image
		try
		{
		   ChartUtilities.saveChartAsJPEG(new File("myChart.jpg"), chart, 500, 300);
		}
		catch (IOException e)
		{
		   System.err.println("Problem occurred creating chart.");
		}


	}
}


/*
package com;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

@Path("helloworld")
public class test {

	@GET
    @Produces("image/png")
    public Response getMessage() throws IOException {
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset.setValue(10, "Profit1", "Jane");
		dataset.setValue(10, "Profit2", "Jane");
		dataset.setValue(7, "Profit1", "Tom");
		dataset.setValue(10, "Profit2", "Tom");
		dataset.setValue(8, "Profit1", "Jill");
		dataset.setValue(8, "Profit2", "Jill");
		dataset.setValue(5, "Profit1", "John");
		dataset.setValue(6, "Profit2", "John");
		dataset.setValue(1, "Profit1", "Fred");
		dataset.setValue(5, "Profit2", "Fred");

		
		final JFreeChart chart = ChartFactory.createBarChart3D(
		   "Comparison between Salesman",  // Chart name
		   "Salesman",                     // X axis label
		   "Value ($)",                    // Y axis value
		   dataset,                        // data set
		   PlotOrientation.VERTICAL,
		   true, true, false);
		
	
                BufferedImage image  = chart.createBufferedImage(600, 600);
                ByteArrayOutputStream byteArray = new ByteArrayOutputStream() ;
                ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
                return Response.ok(new ByteArrayInputStream(byteArray.toByteArray())).build();
            }
              }

*/